<template>
  <a-modal
    :title="title"
    :width="800"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">

    <a-spin :spinning="confirmLoading">
      <a-form :form="form">

        <a-form-item
          :labelCol="labelCol"
          :wrapperCol="wrapperCol"
          label="价格">
          <a-input placeholder="请输入价格" v-decorator="['price', validatorRules.price]" />
        </a-form-item>


      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
import {httpAction, postAction} from '@/api/manage'
  import { ACCESS_TOKEN } from "@/store/mutation-types"
  import { getAction } from '@/api/manage'
  import pick from 'lodash.pick'
  import moment from "moment"
  import Vue from 'vue'

  export default {
    name: "PmsProductPriceEdit",
    data () {
      return {
        title:"操作",
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,

        form: this.$form.createForm(this),
        validatorRules:{
          price: { rules: [{ required: true, message: '请输入商品价格!' }] }
        },
        picUrl: "",
        url: {
          edit: "/pms/pmsProductV2/editPrice",
        },
      }
    },
    created () {

    },
    computed:{

    },
    methods: {

      edit (record) {
        this.form.resetFields();
        this.visible = true;
        this.model = Object.assign({}, record);
        this.model.id=record.id;
        this.$nextTick(() => {
          this.form.setFieldsValue(pick(this.model,'price'))
        });
      },
      moment,

      close () {
        this.$emit('close');
        this.visible = false;
      },
      handleOk () {
        const that = this;
        // 触发表单验证
        this.form.validateFields((err, values) => {
          if (!err) {
            // that.confirmLoading = true;
            let formData = Object.assign(this.model, values);
            //时间格式化
            formData.id=this.model.id;

            postAction(this.url.edit,formData).then((res)=>{
              if(res.success){
                that.$message.success(res.message);
                that.$emit('ok');
              }else{
                that.$message.warning(res.message);
              }
            }).finally(() => {
              // that.confirmLoading = false;
              that.close();
            })
          }
        })
      },
      handleCancel () {
        this.close()
      },
    }
  }
</script>

<style scoped>

</style>